package de.dopichaj.labrador.search.merge;

import java.util.SortedSet;

import de.dopichaj.labrador.search.hit.Hit;
import de.dopichaj.labrador.search.hit.HitHierarchyTree;


/**
 * class to provide easy access to the merge calculation.
 */
public abstract class Merge {

    /**
     * Return value for decideMerge
     */
    public static final int MERGE_UP = 3001;

    /**
     * Return value for decideMerge
     */
    public static final int MERGE_DOWN = 3002;
    
    /**
     * Return value for decideMerge
     */    
    public static final int DO_NOT_MERGE = 3003;

    protected HitHierarchyTree tree;
    
    /**
     * Set the HitHierarchyTree for further merge decisions.
     */
    public void setTree(HitHierarchyTree tree) {
        this.tree = tree;
    }
    
    public abstract String getDescription();
    
    /**
     * Decide upon a merge by returning one of the 
     * decision values.
     * 
     * @param parent The parent hit.
     * @return One of the values MERGE_UP, MERGE_DOWN or DO_NOT_MERGE
     */
    public abstract int decideMerge(Hit parent, SortedSet<Hit> children);
    
    /**
     * Finish merging.
     * This method is called after all calls to decideMerge have been made; it can
     * be used to do any clean-up work. Defaults to doing nothing.
     */
    public void finishMerge() {
        // do nothing unless overridden
    }
}
/*
Copyright (c) 2005 Benedikt Eger
Copyright (c) 2005-2007 Philipp Dopichaj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/